package band.wukong.practice.java.core.topic.concurrency.threadpool;

import java.util.concurrent.*;

/**
 * @author wukong(wukonggg@139.com)
 */
public class ExecutorServiceSample {

    public static void main(String[] args) {
        newFixedThreadPool();
    }

    /**
     * 创建固定数目线程的线程池。
     */
    private static void newFixedThreadPool() {
        Runnable task = () -> System.out.println(Thread.currentThread().getName() + ": 把握时代脉搏！");
        Runnable task2 = () -> System.out.println(Thread.currentThread().getName() + ": 把握时代脉搏！！！");

        ExecutorService executor = Executors.newFixedThreadPool(2);
        for (int i = 0; i < 2; i++) {
            executor.execute(task);
            executor.execute(task2);
        }
        executor.shutdown();
    }

}
